import away3d.core.base.*;
import away3d.core.render.*;
import away3d.extrusions.*;

import com.powerfl.frm.taf.*;
import flash.geom.*;

private function awayChannelGet( $channel:String ):int{
	var channel:int;
	channel = 1;
	switch( $channel.toLowerCase() ){
	case'r':channel = 1; break;
	case'g':channel = 2; break;
	case'b':channel = 4; break;
	case'a':channel = 8; break;
	case'v':channel = 16; break;
	}
	return channel;
}
final public function awayAniUpdate( $tree:String, $animation:String, $time:Number = 0 ):void{
	tdataCall( $tree + '@' + $animation, '', 'update', $time );
}
final public function away_AniUpdate( $tree:String, $animation:String, $time:Number = 0 ):void{
	tdata( $tree + '@' + $animation ).update( $time );
}
	
final public function awayRenderBASIC( $tree:String ):void{
	tdataSet( $tree, '', {renderer:Renderer.BASIC} );
}
final public function away_RenderBASIC( $tree:String ):void{
	tdata( $tree ).renderer = Renderer.BASIC;
}
final public function awayRenderCORRECT( $tree:String ):void{
	tdataSet( $tree, '', {renderer:Renderer.CORRECT_Z_ORDER} );
}
final public function away_RenderCORRECT( $tree:String ):void{
	tdata( $tree ).renderer = Renderer.CORRECT_Z_ORDER;
}
final public function awayRenderINTERSECT( $tree:String ):void{
	tdataSet( $tree, '', {renderer:Renderer.INTERSECTING_OBJECTS} );
}
final public function away_RenderINTERSECT( $tree:String ):void{
	tdata( $tree ).renderer = Renderer.INTERSECTING_OBJECTS;
}
final public function awayCameraSet( $view:String, $x:Number, $y:Number, $z:Number ):void{
	orderAdd( null, away_CameraSet, $view, $x, $y, $z );
}
final public function away_CameraSet( $view:String, $x:Number, $y:Number, $z:Number ):void{
	var camera:*;
	camera = tdata( $view + '@camera' );
	camera.x = $x;
	camera.y = $y;
	camera.z = $z;
}
final public function awayTargetSet( $view:String, $x:Number, $y:Number, $z:Number ):void{
	orderAdd( null, away_TargetSet, $view, $x, $y, $z );
}
final public function away_TargetSet( $view:String, $x:Number, $y:Number, $z:Number ):void{
	var target:*;
	target = tdata( $view + '@target' );
	target.x = $x;
	target.y = $y;
	target.z = $z;
}
final public function awayTreeSet( $tree:String, $x:Number, $y:Number, $z:Number ):void{
	orderAdd( null, away_TreeSet, $tree, $x, $y, $z );
}
final public function away_TreeSet( $tree:String, $x:Number, $y:Number, $z:Number ):void{
	var tree:*;
	tree = tdata( $tree ); 
	tree.x = $x;
	tree.y = $y;
	tree.z = $z;
}
final public function awayCameraFromTree( $view:String, $tree:String, $x:Number, $y:Number, $z:Number ):void{
	orderAdd( null, away_CameraFromTree, $view, $tree, $x, $y, $z );
}
final public function away_CameraFromTree( $view:String, $tree:String, $x:Number, $y:Number, $z:Number ):void{
	var camera:*, tree:*;
	camera = tdata( $view + '@camera' );
	tree = tdata( $tree ); 
	camera.x = tree.x + $x;
	camera.y = tree.y + $y;
	camera.z = tree.z + $z;
}
final public function awayCameraFromTarget( $view:String, $x:Number, $y:Number, $z:Number ):void{
	orderAdd( null, away_CameraFromTarget, $view, $x, $y, $z );
}
final public function away_CameraFromTarget( $view:String, $x:Number, $y:Number, $z:Number ):void{
	var camera:*, target:*;
	camera = tdata( $view + '@camera' );
	target = tdata( $view + '@target' );
	camera.x = target.x + $x;
	camera.y = target.y + $y;
	camera.z = target.z + $z;
}
final public function awayTargetFromTree( $view:String, $tree:String, $x:Number, $y:Number, $z:Number ):void{
	orderAdd( null, away_TargetFromTree, $view, $tree, $x, $y, $z );
}
final public function away_TargetFromTree( $view:String, $tree:String, $x:Number, $y:Number, $z:Number ):void{
	var target:*, tree:*;
	target = tdata( $view + '@target' );
	tree = tdata( $tree ); 
	target.x = tree.x + $x;
	target.y = tree.y + $y;
	target.z = tree.z + $z;
}
final public function awayTargetFromCamera( $view:String, $x:Number, $y:Number, $z:Number ):void{
	orderAdd( null, away_TargetFromCamera, $view, $x, $y, $z );
}
final public function away_TargetFromCamera( $view:String, $x:Number, $y:Number, $z:Number ):void{
	var camera:*, target:*;
	camera = tdata( $view + '@camera' );
	target = tdata( $view + '@target' );
	target.x = camera.x + $x;
	target.y = camera.y + $y;
	target.z = camera.z + $z;
}
final public function awayTreeFromTarget( $view:String, $tree:String, $x:Number, $y:Number, $z:Number ):void{
	orderAdd( null, away_TreeFromTarget, $view, $tree, $x, $y, $z );
}
final public function away_TreeFromTarget( $view:String, $tree:String, $x:Number, $y:Number, $z:Number ):void{
	var target:*, tree:*;
	target = tdata( $view + '@target' );
	tree = tdata( $tree ); 
	tree.x = target.x + $x;
	tree.y = target.y + $y;
	tree.z = target.z + $z;
}
final public function awayTreeFromCamera( $view:String, $tree:String, $x:Number, $y:Number, $z:Number ):void{
	orderAdd( null, away_TreeFromCamera, $view, $tree, $x, $y, $z );
}
final public function away_TreeFromCamera( $view:String, $tree:String, $x:Number, $y:Number, $z:Number ):void{
	var camera:*, tree:*;
	camera = tdata( $view + '@camera' );
	tree = tdata( $tree ); 
	tree.x = camera.x + $x;
	tree.y = camera.y + $y;
	tree.z = camera.z + $z;
}
final public function awayTreeFromElevationLevel( $tree:String, $elevator:String, $ex:String, $ey:String, $offset:String, $x:Number = -2147483648, $y:Number = -2147483648, $z:Number = -2147483648 ):void{
	orderAdd( null, away_TreeFromElevationLevel, $tree, $elevator, $ex, $ey, $offset, $x, $y, $z );
}
final public function away_TreeFromElevationLevel( $tree:String, $elevator:String, $ex:String, $ey:String, $offset:String, $x:Number = -2147483648, $y:Number = -2147483648, $z:Number = -2147483648  ):void{
	var reader:ElevationReader, tree:*;
	reader = tdata( $elevator + '@reader' );
	tree = tdata( $tree );
	tree.y = reader.getLevel( EXPRESSION( $ex, tree ), EXPRESSION( $ey, tree ), EXPRESSION( $offset, tree ) );
	if( $x === $NONE ){}else{
		tree.x += $x;
	}
	if( $y === $NONE ){}else{
		tree.y += $y;
	}
	if( $z === $NONE ){}else{
		tree.z += $z;
	}
}
final public function awayCameraMove( $view:String, $forward:Number = -2147483648, $back:Number = -2147483648, $up:Number = -2147483648, $down:Number = -2147483648, $left:Number = -2147483648, $right:Number = -2147483648 ):void{
	orderAdd( null, away_CameraMove, $view, $forward, $back, $up, $down, $left, $right );
}
final public function away_CameraMove( $view:String, $forward:Number = -2147483648, $back:Number = -2147483648, $up:Number = -2147483648, $down:Number = -2147483648, $left:Number = -2147483648, $right:Number = -2147483648 ):void{
	awayMove( tdata( $view + '@camera' ), $forward, $back, $up, $down, $left, $right );
}
final public function awayTargetMove( $view:String, $forward:Number = -2147483648, $back:Number = -2147483648, $up:Number = -2147483648, $down:Number = -2147483648, $left:Number = -2147483648, $right:Number = -2147483648 ):void{
	orderAdd( null, away_TargetMove, $view,$forward, $back, $up, $down, $left, $right )
}
final public function away_TargetMove( $view:String, $forward:Number = -2147483648, $back:Number = -2147483648, $up:Number = -2147483648, $down:Number = -2147483648, $left:Number = -2147483648, $right:Number = -2147483648 ):void{
	awayMove( tdata( $view + '@target' ), $forward, $back, $up, $down, $left, $right );
}
final public function awayTreeMove( $tree:String, $forward:Number = -2147483648, $back:Number = -2147483648, $up:Number = -2147483648, $down:Number = -2147483648, $left:Number = -2147483648, $right:Number = -2147483648 ):void{
	orderAdd( null, away_TreeMove, $tree, $forward, $back, $up, $down, $left, $right );
}
final public function away_TreeMove( $tree:String, $forward:Number = -2147483648, $back:Number = -2147483648, $up:Number = -2147483648, $down:Number = -2147483648, $left:Number = -2147483648, $right:Number = -2147483648 ):void{
	awayMove( tdata( $tree ), $forward, $back, $up, $down, $left, $right );
}
private function awayMove( $target:Object3D, $forward:Number, $back:Number, $up:Number, $down:Number, $left:Number, $right:Number ):void{
	if( $forward === $NONE ){}else{
		$target.moveForward( $forward );
	}
	if( $back === $NONE ){}else{
		$target.moveBackward( $back );
	}
	if( $up === $NONE ){}else{
		$target.moveUp( $up );
	}
	if( $down === $NONE ){}else{
		$target.moveDown( $down );
	}
	if( $left === $NONE ){}else{
		$target.moveLeft( $left );
	}
	if( $right === $NONE ){}else{
		$target.moveRight( $right );
	}
}
final public function awayCameraRotation( $view:String, $x:Number = -2147483648, $y:Number = -2147483648, $z:Number = -2147483648 ):void{
	orderAdd( null, away_CameraRotation, $view, $x, $y, $z );
}
final public function away_CameraRotation( $view:String, $x:Number = -2147483648, $y:Number = -2147483648, $z:Number = -2147483648 ):void{
	awayRotation( tdata( $view + '@camera' ), $x, $y, $z );
}
final public function awayTargetRotation( $view:String, $x:Number = -2147483648, $y:Number = -2147483648, $z:Number = -2147483648 ):void{
	orderAdd( null, away_TargetRotation, $view, $x, $y, $z );
}
final public function away_TargetRotation( $view:String, $x:Number = -2147483648, $y:Number = -2147483648, $z:Number = -2147483648 ):void{
	awayRotation( tdata( $view + '@target' ), $x, $y, $z );
}
final public function awayTreeRotation( $tree:String, $x:Number = -2147483648, $y:Number = -2147483648, $z:Number = -2147483648 ):void{
	orderAdd( null, away_TreeRotation, $tree, $x, $y, $z );
}
final public function away_TreeRotation( $tree:String, $x:Number = -2147483648, $y:Number = -2147483648, $z:Number = -2147483648 ):void{
	awayRotation( tdata( $tree ), $x, $y, $z );
}
private function awayRotation( $target:Object3D, $x:Number, $y:Number, $z:Number ):void{
	if( $x === $NONE ){}else{
		$target.pitch( $x );
	}
	if( $y === $NONE ){}else{
		$target.yaw( $y );
	}
	if( $z === $NONE ){}else{
		$target.roll( $z );
	}
}
final public function awayCameraFaceTarget( $view:String ):void{
	orderAdd( null, away_CameraFaceTarget, $view );
}
final public function away_CameraFaceTarget( $view:String ):void{
	tdata( $view + '@camera' ).lookAt( tdata( $view + '@target' ).position );
}
final public function awayCameraFaceTree( $view:String, $tree:String ):void{
	orderAdd( null, away_CameraFaceTree, $view, $tree );
}
final public function away_CameraFaceTree( $view:String, $tree:String ):void{
	tdata( $view + '@camera' ).lookAt( tdata( $tree ).position );
}

final public function awayTreeFace( $tree:String, $x:Number, $y:Number, $z:Number ):void{
	orderAdd( null, away_TreeFace, $tree, $x, $y, $z );
}
final public function away_TreeFace( $tree:String, $x:Number, $y:Number, $z:Number ):void{
	tdata( $tree ).lookAt( new flash.geom.Vector3D( $x, $y, $z ) );
}
final public function awayTreeFaceTarget( $view:String, $tree:String ):void{
	orderAdd( null, away_TreeFaceTarget, $view, $tree );
}
final public function away_TreeFaceTarget( $view:String, $tree:String ):void{
	tdata( $tree ).lookAt( tdata( $view + '@target' ).position );
}
final public function awayTreeFaceTree( $view:String, $tree:String ):void{
	orderAdd( null, away_TreeFaceTree, $view, $tree );
}
final public function away_TreeFaceTree( $view:String, $tree:String ):void{
	tdata( $tree ).lookAt( tdata( $view + '@camera' ).position );
}